import { PERMISSIONS, USERRESULT, getItem, hsHandleTableDateTime, isDate } from '@hs-admin/utils'

export function handleButtonShow(auth: string, id?: string | string[]) {
  let flag = false
  const permissions = getItem(PERMISSIONS)
  const userResult = getItem(USERRESULT)
  if (auth && permissions?.includes(auth)) {
    flag = true
  }
  if (id) {
    let ids: string | any[] = []
    if (Array.isArray(id)) {
      ids = id
    } else if (typeof id === 'string') {
      ids = [id]
    }
    if (ids.includes(userResult?.id)) {
      flag = true
    }
  }
  return flag
}

// 处理表格中返回数据为日期格式的字符串
export function handleTableShowDate(item: any, key: string) {
  if (isDate(item[key]) && isNaN(item[key]) && item[key].length !== 10) {
    item[key] = hsHandleTableDateTime(item[key])
  }
}
